﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

using BusinessManagementStudio.Models.BusinessObject.Entities;
using MongoDB.Driver.Builders;
using MongoDB.Driver.Linq;

namespace BusinessManagementStudio.Models.BusinessObject.Services
{
    public class ClientService : EntityService<Client>
    {
        public List<Client> GetAllClients()
        {
            return (from client in this.MongoConnectionHandler.MongoCollection.FindAllAs<Client>()
                    select client).ToList();
        }

        // For Company 7
        public Client GetClient(String CompanyCode)
        {
            return (from client in this.MongoConnectionHandler.MongoCollection.FindAllAs<Client>()
                    where client.CompanyName == CompanyCode
                    select client).FirstOrDefault();
        }

        // For Company 3
        public Client GetClient(String CompanyCode, String FMCode)
        {
            return (from client in this.MongoConnectionHandler.MongoCollection.FindAllAs<Client>()
                    where client.CompanyName == CompanyCode && client.FMCode == FMCode
                    select client).FirstOrDefault();
        }

        public override void Update(Client entity)
        {
            //// Not necessary for the example
        }
    }
}